from apps.system.router.baseViews import *

def findListByRole(self):
    _list = self.request.user.role.routers.all().filter(is_delete=0)
    return _list

class RouterForRoleViewSet(BaseRouterViewSet):

    def get_queryset(self):
        print('当前角色', self.request.user.role.key)
        _list = findListByRole(self)
        return _list.order_by('sort', '-id')

class RouterViewSet(BaseRouterViewSet):

    def get_queryset(self):
        _list = []
        if self.request.user.role.key == 'admin' or self.request.user.role.key == 'superAdmin':
            _list = RouterDao().findAll().order_by('sort', '-id')
        else:
            _list = findListByRole(self)
        return _list.order_by('sort', '-id')